home *** CD-ROM | disk | FTP | other *** search
/ CD/PC Actual Thematic 7: Programming / CDAT7.iso / Share / Codigo / hh / rsource.exe / Hexen Source / P_PLATS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-22  |  6.2 KB  |  267 lines

  1.  
  2. //**************************************************************************
  3. //**
  4. //** p_plats.c : Heretic 2 : Raven Software, Corp.
  5. //**
  6. //** $RCSfile: p_plats.c,v $
  7. //** $Revision: 1.11 $
  8. //** $Date: 95/09/11 22:06:30 $
  9. //** $Author: cjr $
  10. //**
  11. //**************************************************************************
  12.  
  13. #include "h2def.h"
  14. #include "p_local.h"
  15. #include "soundst.h"
  16.  
  17. plat_t  *activeplats[MAXPLATS];
  18.  
  19. //==================================================================
  20. //
  21. //      Move a plat up and down
  22. //
  23. //==================================================================
  24. void T_PlatRaise(plat_t *plat)
  25. {
  26.     result_e res;
  27.  
  28.     switch(plat->status)
  29.     {
  30.         case PLAT_UP:
  31.             res = T_MovePlane(plat->sector, plat->speed,
  32.                     plat->high, plat->crush, 0, 1);
  33.             if (res == RES_CRUSHED && (!plat->crush))
  34.             {
  35.                 plat->count = plat->wait;
  36.                 plat->status = PLAT_DOWN;
  37.                 SN_StartSequence((mobj_t *)&plat->sector->soundorg, 
  38.                     SEQ_PLATFORM+plat->sector->seqType);
  39.             }
  40.             else
  41.             if (res == RES_PASTDEST)
  42.             {
  43.                 plat->count = plat->wait;
  44.                 plat->status = PLAT_WAITING;
  45.                 SN_StopSequence((mobj_t *)&plat->sector->soundorg);
  46.                 switch(plat->type)
  47.                 {
  48.                     case PLAT_DOWNWAITUPSTAY:
  49.                     case PLAT_DOWNBYVALUEWAITUPSTAY:
  50.                         P_RemoveActivePlat(plat);
  51.                         break;
  52.                     default:
  53.                         break;
  54.                 }
  55.             }
  56.             break;
  57.         case PLAT_DOWN:
  58.             res = T_MovePlane(plat->sector,plat->speed,plat->low,false,0,-1);
  59.             if (res == RES_PASTDEST)
  60.             {
  61.                 plat->count = plat->wait;
  62.                 plat->status = PLAT_WAITING;
  63.                 switch(plat->type)
  64.                 {
  65.                     case PLAT_UPWAITDOWNSTAY:
  66.                     case PLAT_UPBYVALUEWAITDOWNSTAY:
  67.                         P_RemoveActivePlat(plat);
  68.                         break;
  69.                     default:
  70.                         break;
  71.                 }
  72.                 SN_StopSequence((mobj_t *)&plat->sector->soundorg);
  73.             }
  74.             break;
  75.         case PLAT_WAITING:
  76.             if (!--plat->count)
  77.             {
  78.                 if (plat->sector->floorheight == plat->low)
  79.                     plat->status = PLAT_UP;
  80.                 else
  81.                     plat->status = PLAT_DOWN;
  82.                 SN_StartSequence((mobj_t *)&plat->sector->soundorg, 
  83.                     SEQ_PLATFORM+plat->sector->seqType);
  84.             }
  85. //        case PLAT_IN_STASIS:
  86. //            break;
  87.     }
  88. }
  89.  
  90. //==================================================================
  91. //
  92. //      Do Platforms
  93. //      "amount" is only used for SOME platforms.
  94. //
  95. //==================================================================
  96. int EV_DoPlat(line_t *line, byte *args, plattype_e type, int amount)
  97. {
  98.     plat_t          *plat;
  99.     int                     secnum;
  100.     int                     rtn;
  101.     sector_t        *sec;
  102.  
  103.     secnum = -1;
  104.     rtn = 0;
  105.  
  106. /*
  107.     //
  108.     //      Activate all <type> plats that are in_stasis
  109.     //
  110.     switch(type)
  111.     {
  112.         case PLAT_PERPETUALRAISE:
  113.             P_ActivateInStasis(args[0]);
  114.             break;
  115.         default:
  116.             break;
  117.     }
  118. */
  119.  
  120.     while ((secnum = P_FindSectorFromTag(args[0], secnum)) >= 0)
  121.     {
  122.         sec = §ors[secnum];
  123.         if (sec->specialdata)
  124.             continue;
  125.  
  126.         //
  127.         // Find lowest & highest floors around sector
  128.         //
  129.         rtn = 1;
  130.         plat = Z_Malloc( sizeof(*plat), PU_LEVSPEC, 0);
  131.         P_AddThinker(&plat->thinker);
  132.  
  133.         plat->type = type;
  134.         plat->sector = sec;
  135.         plat->sector->specialdata = plat;
  136.         plat->thinker.function = T_PlatRaise;
  137.         plat->crush = false;
  138.         plat->tag = args[0];
  139.         plat->speed = args[1]*(FRACUNIT/8);
  140.         switch(type)
  141.         {
  142.             case PLAT_DOWNWAITUPSTAY:
  143.                 plat->low = P_FindLowestFloorSurrounding(sec)+8*FRACUNIT;
  144.                 if (plat->low > sec->floorheight)
  145.                     plat->low = sec->floorheight;
  146.                 plat->high = sec->floorheight;
  147.                 plat->wait = args[2];
  148.                 plat->status = PLAT_DOWN;
  149.                 break;
  150.             case PLAT_DOWNBYVALUEWAITUPSTAY:
  151.                 plat->low = sec->floorheight-args[3]*8*FRACUNIT;
  152.                 if (plat->low > sec->floorheight)
  153.                     plat->low = sec->floorheight;
  154.                 plat->high = sec->floorheight;
  155.                 plat->wait = args[2];
  156.                 plat->status = PLAT_DOWN;
  157.                 break;
  158.             case PLAT_UPWAITDOWNSTAY:
  159.                 plat->high = P_FindHighestFloorSurrounding(sec);
  160.                 if (plat->high < sec->floorheight)
  161.                     plat->high = sec->floorheight;
  162.                 plat->low = sec->floorheight;
  163.                 plat->wait = args[2];
  164.                 plat->status = PLAT_UP;
  165.                 break;
  166.             case PLAT_UPBYVALUEWAITDOWNSTAY:
  167.                 plat->high = sec->floorheight+args[3]*8*FRACUNIT;
  168.                 if (plat->high < sec->floorheight)
  169.                     plat->high = sec->floorheight;
  170.                 plat->low = sec->floorheight;
  171.                 plat->wait = args[2];
  172.                 plat->status = PLAT_UP;
  173.                 break;
  174.             case PLAT_PERPETUALRAISE:
  175.                 plat->low = P_FindLowestFloorSurrounding(sec)+8*FRACUNIT;
  176.                 if (plat->low > sec->floorheight)
  177.                     plat->low = sec->floorheight;
  178.                 plat->high = P_FindHighestFloorSurrounding(sec);
  179.                 if (plat->high < sec->floorheight)
  180.                     plat->high = sec->floorheight;
  181.                 plat->wait = args[2];
  182.                 plat->status = P_Random()&1;
  183.                 break;
  184.         }
  185.         P_AddActivePlat(plat);
  186.         SN_StartSequence((mobj_t *)&sec->soundorg, SEQ_PLATFORM+sec->seqType);
  187.     }
  188.     return rtn;
  189. }
  190.  
  191. #if 0
  192. void P_ActivateInStasis(int tag)
  193. {
  194.     int             i;
  195.  
  196.     for (i = 0;i < MAXPLATS;i++)
  197.         if (activeplats[i] &&
  198.             (activeplats[i])->tag == tag &&
  199.             (activeplats[i])->status == PLAT_IN_STASIS)
  200.         {
  201.             (activeplats[i])->status = (activeplats[i])->oldstatus;
  202.             (activeplats[i])->thinker.function = T_PlatRaise;
  203.         }
  204. }
  205. #endif
  206.  
  207. void EV_StopPlat(line_t *line, byte *args)
  208. {
  209.     int i;
  210.  
  211.     for(i = 0; i < MAXPLATS; i++)
  212.     {
  213.         if((activeplats[i])->tag = args[0])
  214.         {
  215.             (activeplats[i])->sector->specialdata = NULL;
  216.             P_TagFinished((activeplats[i])->sector->tag);
  217.             P_RemoveThinker(&(activeplats[i])->thinker);
  218.             activeplats[i] = NULL;
  219.  
  220.             return;
  221.         }
  222.     }
  223.  
  224. /*
  225.     int             j;
  226.  
  227.     for (j = 0;j < MAXPLATS;j++)
  228.     {
  229.         if (activeplats[j] && ((activeplats[j])->status != PLAT_IN_STASIS) &&
  230.             ((activeplats[j])->tag == args[0]))
  231.         {
  232.             (activeplats[j])->oldstatus = (activeplats[j])->status;
  233.             (activeplats[j])->status = PLAT_IN_STASIS;
  234.             (activeplats[j])->thinker.function = NULL;
  235.             SN_StopSequence((mobj_t *)&(activeplats[j])->sector->soundorg);
  236.         }
  237.     }
  238. */
  239. }
  240.  
  241. void P_AddActivePlat(plat_t *plat)
  242. {
  243.     int             i;
  244.     for (i = 0;i < MAXPLATS;i++)
  245.         if (activeplats[i] == NULL)
  246.         {
  247.             activeplats[i] = plat;
  248.             return;
  249.         }
  250.     I_Error ("P_AddActivePlat: no more plats!");
  251. }
  252.  
  253. void P_RemoveActivePlat(plat_t *plat)
  254. {
  255.     int             i;
  256.     for (i = 0;i < MAXPLATS;i++)
  257.         if (plat == activeplats[i])
  258.         {
  259.             (activeplats[i])->sector->specialdata = NULL;
  260.             P_TagFinished(plat->sector->tag);
  261.             P_RemoveThinker(&(activeplats[i])->thinker);
  262.             activeplats[i] = NULL;
  263.             return;
  264.         }
  265.     I_Error ("P_RemoveActivePlat: can't find plat!");
  266. }
  267.